/**
 * 
 */
package cc.monggo.util.filesystem;

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

/**
 * @author fangjinsong
 *
 */
public class ExcelUtils {

	/**
	 * 读取表格Excel内容，并安列存放在内存中
	 * @param path
	 * @return
	 */
	public static Map readExcel(String path){
		Map map = new HashMap();
		return map;
	}
	
	/**
	 * 输出输出到Excel文件
	 * @param output
	 * @param data
	 */
	public static void writeExcelToFileSystem(String path,Map<String,List> data){
        try {
            WritableWorkbook book = Workbook.createWorkbook(new File(path));
            WritableSheet sheet = book.createSheet("第1页", 0);
    		Iterator<String> it = data.keySet().iterator();
    		int k = 0;
    		while(it.hasNext()){
    			String key = it.next();
    			List<String> list = data.get(key);
    			//1.获取表格的首行
    			Label headLine = new Label(k,0,key);
    			sheet.addCell(headLine);
    			//2.获取表格内容
    			for(int i=0;i<list.size();i++){
    				String s = list.get(i) + "";
    				Label label = new Label(k,i+1,s);
    				sheet.addCell(label);
    			}
    			k++;
    		}
            // 写入数据并关闭文件
            book.write();
            book.close();

        } catch (Exception e) {
        }
	}

}
